package com.oragraph.data;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

public class Properties {
	
	private Hashtable<String,String> _properties;
	private Vector<PropertiesChangeListener> _changeListeners;
	private Object _owner;
	
	public Properties() {
		_properties=new Hashtable<String,String>();
		_changeListeners=new Vector<PropertiesChangeListener>();
	}
	
	public void setOwner(Object owner) {
		_owner=owner;
	}
	
	public Object getOwner() {
		return _owner;
	}
	
	public void addChangeListener(PropertiesChangeListener listener) {
		if (!_changeListeners.contains(listener)) _changeListeners.add(listener);
	}
	
	public void removeChangeListener(PropertiesChangeListener listener) {
		_changeListeners.remove(listener);
	}
	
	public void set(String key, String value) {
		boolean existed=_properties.containsKey(key);
		_properties.put(key, value);
		for (int i=0; i<_changeListeners.size(); i++) {
			if (existed) _changeListeners.elementAt(i).propertyChanged(this, key);
			else _changeListeners.elementAt(i).propertyAdded(this, key);
		}
	}
	
	public String get(String key) {
		return _properties.get(key);
	}

	public Enumeration<String> keys() {
		return _properties.keys();
	}
}
